<?php
/**
 *User :门前一棵柿子树
 *Date:2024/4/15
 *Email:785313152@qq.com
 */

namespace app\admin\controller;

use app\admin\model\ProposeClassify;
use app\common\controller\AdminBase;
use app\index\model\ProposeLog;

class Propose extends AdminBase
{
    public $model;
    protected function _initialize()
    {
        $cate = ProposeClassify::column('name', 'id');
        $status = [
            0 => "已关闭",
            1 => "已发起",
            2 => "审核中",
            3 => "已通过",
            4 => "待分配",
            5 => "待执行",
            6 => "已完成"
        ];
        $this->assign('cate', $cate);
        $this->assign('status', $status);
        $this->model = new \app\admin\model\Propose();
        parent::_initialize();
    }

    public function index(){
        return $this->fetch();
    }

    public function getLists()
    {
        if ($this->request->isAjax()) {
            return $this->model->getLists();
        }
    }
    public function output(){
        $m = new \app\admin\model\Jdz();
        return $this->model->output();
    }

    public function detail(){
        $id = input('id');
        $rows = $this->model->find($id)->toArray();
        $this->assign('rows', $rows);
        $department = cache('department_list');
        $department = array_column($department['department'], 'name', 'id');
        $this->assign('department', $department);
        $log = ProposeLog::where('propose_id', '=', $id)->order('add_time desc')->select()->toArray();
        $this->assign('log', $log);
        return $this->fetch();
    }

    public function changes_status(){
        if($this->request->isAjax()){
            $data['status']=input('status');
            $id = input('id');

            if($this->model->isUpdate(true)->save($data,['id'=>$id])!==false){
                return ajax_return(1,'提交成功');
            }
            return ajax_return(0,'提交失败');
        }
        return $this->fetch();
    }
}